<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>缺陷级别确认页面</title>
    <link rel="stylesheet" href="../lib/layui/css/layui.css" media="all">
</head>
<body>
<!--缺陷级别确认页面-->
<form id="popupForm" class="layui-form layui-form-pane" method="post">
    <input type="hidden" th:value="${id}" name="id">
    <div class="layui-inline">
        <label class="layui-form-label">缺陷级别</label>
        <div class="layui-input-inline">
            <select name="bugLevel" lay-filter="xmFilter" lay-verify="required|bugLevel">
                <option value="" selected></option>
                <option  th:each="bueLevel : ${bugLevelList}" th:value="${bueLevel.configValueId}"
                         th:text="${bueLevel.configValueName}" >
                </option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="confirmSave">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>


<script src="../lib/layui/layui.js" charset="utf-8"></script>
<script src="../js/jquery.min.js" charset="utf-8"></script>


<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate;

        //监听submit提交按钮 button ，lay-filter 为 userAdd 的
        form.on('submit(confirmSave)', function(data){
            var formData = data.field;
            var bugLevel = formData.bugLevel;
            var id = formData.id;
            //此段代码可以获取提交的数据
            /* layer.alert(JSON.stringify(data.field), {
                 title: '最终的提交信息'
             })*/
            //ajax 提交
            console.log($('#popupForm').serialize())
            $.ajax({
                type: "POST",
                dataType: "text",
                url: "/flaw/confirm_save" ,//url
                data: {id:id,bugLevel:bugLevel},  //表单数据
                success: function (result) {
                    if (result = "seccess") {
                        layer.msg('确认成功，1秒后自动关闭该窗口');
                        //延迟1秒执行，目的是让用户看到提示
                        setTimeout( function(){
                            //1、先得到当前iframe层（弹出层）的索引  ///2、提交成功关闭弹出层窗口
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 1 * 1000 );
                    };
                },
                error : function() {
                    layer.msg('后台异常！未添加成功');
                }
            });
            //阻止页面跳转
            return false;
        });

        //自定义表单验证
        //required 为必填项
        form.verify({
            bugLevel:function(value){
                if (value.length < 1) {
                    return "请选择缺陷级别！";
                }
            }
        });
    });
</script>



</body>
</html>